package com.example.myerp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.myerp.pojo.S_reasonexact;
import com.example.myerp.mapper.S_reasonexactMapper;
import com.example.myerp.service.S_reasonexactService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.myerp.until.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author zhuxingyu
 * @since 2021-08-12
 */
@Service
public class S_reasonexactServiceImpl implements S_reasonexactService {

    @Autowired
    S_reasonexactMapper mapper;
    @Autowired
    RedisUtil redisUtil;

    @Override
    public IPage<S_reasonexact> selectvo(Long pageNum, Long pageSize) {
        Page<S_reasonexact> page = new Page<S_reasonexact>(pageNum, pageSize, true);
        return mapper.selectvo(page);
    }

    @Override
    public Integer s_reasonexactAdd(String reasonexact) {
        redisUtil.del("reasonList");
        return mapper.insert(new S_reasonexact(null, reasonexact));
    }

    @Override
    public Integer s_reasonexactdel(Long rctid) {
        redisUtil.del("reasonList");
        return mapper.deleteById(rctid);

    }

    @Override
    public List<S_reasonexact> reasonList() {
        List<S_reasonexact> lis = new ArrayList<>();
        if (redisUtil.hasKey("reasonList")) {
            lis = (List<S_reasonexact>) redisUtil.get("reasonList");
        } else {
            lis = mapper.reasonList();
            redisUtil.set("reasonList", lis);
        }
        return lis;
    }

    @Override
    public List<S_reasonexact> selectAll() {
        QueryWrapper<S_reasonexact> object = new QueryWrapper<S_reasonexact>();
        object.gt("rctid", 0);
        List<S_reasonexact> s_reasonexacts = mapper.selectList(object);
        return s_reasonexacts;
    }
}
